package org.sun.sunshine.config;

import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;

public class TokenUtil {


    public static void main(String[] args) {
        try {
            // 生成密钥对
            KeyPair keyPair = SignatureUtil.generateKeyPair();
            PublicKey publicKey = keyPair.getPublic();
            System.out.println("Public Key: " + SignatureUtil.publicKeyToString(publicKey));
            PrivateKey privateKey = keyPair.getPrivate();
            System.out.println("Private Key: " + SignatureUtil.privateKeyToString(privateKey));


            // 原始数据
            String originalText = "systemId";
            byte[] data = originalText.getBytes();
            //byte[] 转 String
            String systemId = new String(data);
            System.out.println(systemId);
            // 对数据进行签名
            byte[] signature = SignatureUtil.sign(data, privateKey);
            // 验证签名
            boolean isVerified = SignatureUtil.verify(data, signature, publicKey);
            System.out.println("Signature Verified: " + isVerified);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
